package cn.iocoder.yudao.module.game.service.agentSummary;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.game.controller.admin.agentSummary.vo.*;
import cn.iocoder.yudao.module.game.dal.dataobject.agentSummary.AgentSummaryDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.game.dal.mysql.agentSummary.AgentSummaryMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.game.enums.ErrorCodeConstants.*;

/**
 * 代理汇总 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class AgentSummaryServiceImpl implements AgentSummaryService {

    @Resource
    private AgentSummaryMapper agentSummaryMapper;

    @Override
    public Long createAgentSummary(AgentSummarySaveReqVO createReqVO) {
        // 插入
        AgentSummaryDO agentSummary = BeanUtils.toBean(createReqVO, AgentSummaryDO.class);
        agentSummaryMapper.insert(agentSummary);
        // 返回
        return agentSummary.getId();
    }

    @Override
    public void updateAgentSummary(AgentSummarySaveReqVO updateReqVO) {
        // 校验存在
        validateAgentSummaryExists(updateReqVO.getId());
        // 更新
        AgentSummaryDO updateObj = BeanUtils.toBean(updateReqVO, AgentSummaryDO.class);
        agentSummaryMapper.updateById(updateObj);
    }

    @Override
    public void deleteAgentSummary(Long id) {
        // 校验存在
        validateAgentSummaryExists(id);
        // 删除
        agentSummaryMapper.deleteById(id);
    }

    private void validateAgentSummaryExists(Long id) {
        if (agentSummaryMapper.selectById(id) == null) {
            throw exception(AGENT_SUMMARY_NOT_EXISTS);
        }
    }

    @Override
    public AgentSummaryDO getAgentSummary(Long id) {
        return agentSummaryMapper.selectById(id);
    }

    @Override
    public PageResult<AgentSummaryDO> getAgentSummaryPage(AgentSummaryPageReqVO pageReqVO) {
        return agentSummaryMapper.selectPage(pageReqVO);
    }

}